Skip to content

Commit

Permalink
added instructions to cross compile on linux for windows
Browse files Browse the repository at this point in the history
build a statically linked executable
  • Loading branch information
ferkulat committed May 5, 2019
1 parent 8a97f51 commit 27f0345
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
23 changes: 23 additions & 0 deletions BUILD_SPECIAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Build for windows on linux

Assuming the host platform is "arch linux".

install from [AUR](https://aur.archlinux.org/):
1. mingw-w64-gcc-base
2. mingw-w64-gcc
3. mingw-w64-libiconv

After that you will have following tool chains available:

- /usr/i686-w64-mingw32
- /usr/x86_64-w64-mingw32


git checkout https://github.com/ferkulat/csv2xls.git
cd csv2xls
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/modules/Toolchain-mingw.cmake ..
cmake --build .

This builds with tool chain 'i686-w64-mingw32'. If you want to build with another tool chain, you need to change it in file 'Toolchain-mingw.cmake'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ add_subdirectory(csv2xlslib)
add_subdirectory(csv2xlslib.Test )
add_executable(csv2xls csv2xls.cpp ${version_file})
target_compile_options( csv2xls PUBLIC ${WARNINGOPTS} )
target_link_libraries(csv2xls csv2xlslib )
target_link_libraries(csv2xls csv2xlslib -static)

install(TARGETS csv2xls DESTINATION bin)
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ csv2xls (csv to xls) is a command line utility which converts csv files into one
cd build
cmake ..
cmake --build .

For other build targets, please have a look at [BUILD_SPECIAL.md](BUILD_SPECIAL.md)
### Documentaion

- Print help: csv2xls -h
- manual page: man csv2xls
- https://github.com/ferkulat/csv2xls/wiki

### How to contribute

Expand Down
19 changes: 19 additions & 0 deletions cmake/modules/Toolchain-mingw.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)

SET(MINGW_CHAIN i686-w64-mingw32)
SET(I_USE_MINGW true)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER ${MINGW_CHAIN}-gcc)
SET(CMAKE_CXX_COMPILER ${MINGW_CHAIN}-g++)
SET(CMAKE_RC_COMPILER ${MINGW_CHAIN}-windres)

# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /usr/${MINGW_CHAIN} )

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
2 changes: 1 addition & 1 deletion cmake/modules/xlslib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(EXTERN_XLSLIB_DIR ${EXTERN_DEPENDENCIES_DIR}/xlslib)
FetchContent_Declare(
xlslib
GIT_REPOSITORY https://github.com/ferkulat/xlslib.git
GIT_TAG 227776845cca16a50213359c58c7b9e8264520d9
GIT_TAG 28fb458bc5ba2da614f4738d9560a6fb917d49a9
SOURCE_DIR ${EXTERN_XLSLIB_DIR}
)
FetchContent_MakeAvailable(xlslib)
Expand Down
10 changes: 6 additions & 4 deletions csv2xlslib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ add_library(csv2xlslib
csv2xls_types.cpp)
target_compile_options( csv2xlslib PUBLIC ${WARNINGOPTS} )
target_include_directories(csv2xlslib SYSTEM PRIVATE ${CMAKE_PREFIX_PATH}/include/xlslib)
message("CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}" )
if( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_link_libraries(csv2xlslib xlslib csv )
endif()
if( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
target_link_libraries(csv2xlslib xlslib csv stdc++fs)
target_link_libraries(csv2xlslib xlslib csv -static)
elseif(I_USE_MINGW)
target_link_libraries(csv2xlslib xlslib csv iconv -static)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU")
target_link_libraries(csv2xlslib xlslib csv stdc++fs -static)
endif()

0 comments on commit 27f0345

Please sign in to comment.