Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow static and shared lib #209

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ matrix:
- name: "linux focal gcc release fortran python"
os: linux
dist: focal
sudo: true
sudo: false
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Release" -DCMAKE_UNITY_BUILD_BATCH_SIZE=100000 # this is the strictest test for the unity build.
Expand All @@ -86,6 +86,24 @@ matrix:
- cmake
- python3-setuptools

- name: "linux focal gcc debug fortran python STATIC"
os: linux
dist: focal
sudo: false
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DWB_LIB_BUILD_SHARED=FALSE"
- MATRIX_EVAL="export PATH=/usr/bin/:$PATH"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gfortran
- swig
- cmake
- python3-setuptools

- name: "windows debug VS 2017 python"
os: windows
language: cpp
Expand All @@ -98,6 +116,18 @@ matrix:
- FC=gfortran
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON"

- name: "windows debug VS 2017 python STATIC"
os: windows
language: cpp
env:
- MATRIX_EVAL="which gcc && choco install python --version=3.8.0 -y && choco install swig --version=4.0.1 -y"
- PYTHONPATH=C:/Python38/Lib
- PYTHONHOME=C:/Python38
- PATH=C:/Python38:${PATH}
- MAKE_FILE_GENERATOR="Visual Studio 15 2017 Win64"
- FC=gfortran
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON -DWB_LIB_BUILD_SHARED=FALSE"

- name: "windows release VS 2017 python"
os: windows
language: cpp
Expand Down Expand Up @@ -192,14 +222,14 @@ matrix:

- name: "linux trusty clang fortran python"
os: linux
dist: trusty
dist: focal
sudo: false
os: linux
compiler:
- clang-3.6
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- MATRIX_EVAL="gfortran --version && CC=clang-3.6 && CXX=clang++-3.6 && GC=gfortran"
- MATRIX_EVAL="gfortran --version && CC=clang-3.6 && CXX=clang++-3.6 && GC=gfortran && export PATH=/usr/bin/:$PATH"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-Werror"
addons:
apt:
Expand All @@ -213,6 +243,29 @@ matrix:
- swig
- python3-setuptools

- name: "linux trusty clang fortran python STATIC"
os: linux
dist: focal
sudo: false
os: linux
compiler:
- clang-3.6
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- MATRIX_EVAL="gfortran --version && CC=clang-3.6 && CXX=clang++-3.6 && GC=gfortran && export PATH=/usr/bin/:$PATH"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-Werror -DWB_LIB_BUILD_SHARED=FALSE"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.6
packages:
- clang-3.6
- gfortran
- cmake
- swig
- python3-setuptools

- name: "osx clang fortran python"
sudo: false
os: osx
Expand Down Expand Up @@ -240,12 +293,23 @@ matrix:
os: osx
compiler:
- clang
osx_image: xcode11.6
osx_image: xcode12
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- MATRIX_EVAL="export PATH=$TRAVIS_ROOT/bin:$PATH && which clang && brew install swig || true"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-Werror"

- name: "osx clang fortran python STATIC"
sudo: false
os: osx
compiler:
- clang
osx_image: xcode12
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- MATRIX_EVAL="export PATH=$TRAVIS_ROOT/bin:$PATH && which clang && brew install swig || true"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-Werror -DWB_LIB_BUILD_SHARED=FALSE"

- name: "windows debug mingw fortran"
os: windows
language: cpp
Expand All @@ -268,12 +332,9 @@ matrix:
os: linux
dist: xenial
sudo: false
compiler:
#- g++-6
env:
- MAKE_FILE_GENERATOR="Unix Makefiles"
- CMAKE_EXTRA_ARGS="${CMAKE_EXTRA_ARGS} -DCMAKE_BUILD_TYPE=Release"
#- MATRIX_EVAL="gfortran --version && CC=gcc-6 && CXX=g++-6 && FC=gfortran"
addons:
apt:
sources:
Expand Down
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ endif()

set(SOURCES ${SOURCES_CXX} ${SOURCES_FORTAN})

set(CMAKE_UNITY_BUILD_BATCH_SIZE 5000)

# Special treatment of some files for unity builds. We disable the unity
# build for them.
Expand All @@ -173,7 +172,15 @@ FOREACH(_source_file ${UNITY_DISABLE_FILES})
SET_PROPERTY(SOURCE ${_source_file} PROPERTY SKIP_UNITY_BUILD_INCLUSION TRUE)
ENDFOREACH()

add_library(WorldBuilder ${SOURCES})
SET(WB_LIB_BUILD_SHARED ON CACHE BOOL "Whether to build and link a shared or static library version of the World Builder library.")

if(${WB_LIB_BUILD_SHARED})
add_library(WorldBuilder SHARED ${SOURCES})
Message(STATUS "Build the World Builder library as a shared library.")
else()
add_library(WorldBuilder STATIC ${SOURCES})
Message(STATUS "Build the World Builder library as a static library.")
endif()

IF(NOT CMAKE_VERSION VERSION_LESS 3.16)
SET(WB_UNITY_BUILD ON CACHE BOOL "Combine source files into less compile targets to speedup compile time. Currently only supported for cmake 3.16 and newer versions.")
Expand Down Expand Up @@ -332,13 +339,16 @@ endif()


# Make sure that the whole library is loaded, so the registration is done correctly.
if(NOT APPLE AND NOT MSVC)
if(WB_LIB_BUILD_SHARED)
SET(GWB_LIBRARY_WHOLE WorldBuilder)
elseif(NOT APPLE AND NOT MSVC)
SET(GWB_LIBRARY_WHOLE -Wl,--whole-archive WorldBuilder -Wl,--no-whole-archive)
elseif(MSVC)
SET(GWB_LIBRARY_WHOLE WorldBuilder)
else()
SET(GWB_LIBRARY_WHOLE -Wl,-force_load WorldBuilder)
endif()

target_link_libraries (WorldBuilderApp ${GWB_LIBRARY_WHOLE})
target_link_libraries (WorldBuilderVisualization ${GWB_LIBRARY_WHOLE})

Expand Down
61 changes: 44 additions & 17 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ foreach(test_source ${UNIT_TEST_SOURCES})
endif()

# Make sure that the whole library is loaded, so the registration is done correctly.
if(NOT APPLE)
SET(GWB_LIBRARY_WHOLE -Wl,--whole-archive WorldBuilder -Wl,--no-whole-archive)
if(WB_LIB_BUILD_SHARED)
SET(GWB_LIBRARY_WHOLE WorldBuilder)
elseif(NOT APPLE AND NOT MSVC)
SET(GWB_LIBRARY_WHOLE -Wl,--whole-archive WorldBuilder -Wl,--no-whole-archive)
elseif(MSVC)
SET(GWB_LIBRARY_WHOLE WorldBuilder)
SET(CMAKE_EXE_LINKER_FLAGS "/WHOLEARCHIVE:libworldbuilder")
else()
SET(GWB_LIBRARY_WHOLE -Wl,-force_load WorldBuilder)
endif()
Expand Down Expand Up @@ -154,15 +155,28 @@ endforeach(test_source)
#test fortran compilation and wrapper if compiler found
if(CMAKE_Fortran_COMPILER)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran)
if(NOT APPLE)
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ -Wl,--whole-archive -lWorldBuilder -Wl,--no-whole-archive -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
if(NOT APPLE)
if(${WB_LIB_BUILD_SHARED})
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ -lWorldBuilder -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
else()
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ -Wl,--whole-archive -lWorldBuilder -Wl,--no-whole-archive -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
endif()
else()
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ -Wl,-force_load,../../lib/libWorldBuilder.a -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
if(${WB_LIB_BUILD_SHARED})
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ ../../lib/libWorldBuilder.so -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
else()
add_test(NAME compile_simple_fortran_test
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/test.f90 -L../../lib/ -Wl,-force_load,../../lib/libWorldBuilder.a -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o test${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
endif()
endif()

add_test(run_simple_fortran_test
${CMAKE_COMMAND}
-D TEST_NAME=run_simple_fortran_test
Expand All @@ -174,15 +188,28 @@ if(CMAKE_Fortran_COMPILER)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran)

if(NOT APPLE)
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ -Wl,--whole-archive -lWorldBuilder -Wl,--no-whole-archive -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
if(NOT APPLE)
if(${WB_LIB_BUILD_SHARED})
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ -lWorldBuilder -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
else()
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ -Wl,--whole-archive -lWorldBuilder -Wl,--no-whole-archive -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lstdc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
endif()
else()
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ -Wl,-force_load,../../lib/libWorldBuilder.a -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
if(${WB_LIB_BUILD_SHARED})
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ ../../lib/libWorldBuilder.so -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
else()
add_test(NAME compile_simple_fortran_example
COMMAND ${CMAKE_Fortran_COMPILER} ${CMAKE_CURRENT_SOURCE_DIR}/fortran/example.f90 -L../../lib/ -Wl,-force_load,../../lib/libWorldBuilder.a -I../../mod/ ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -o example${CMAKE_EXECUTABLE_SUFFIX} ${WB_FORTRAN_COMPILER_FLAGS_COVERAGE} -lc++
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fortran/)
endif()
endif()

add_test(run_simple_fortran_example
${CMAKE_COMMAND}
-D TEST_NAME=run_simple_fortran_example
Expand Down
2 changes: 1 addition & 1 deletion tests/python/run_python_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(EXECUTE_COMMAND ${TEST_PROGRAM} ${TEST_ARGS})
# run the test program, capture the stdout/stderr and the result var ${TEST_ARGS}
execute_process(
COMMAND ${TEST_PROGRAM} ${TEST_ARGS} -i ${TEST_INPUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/fortran/
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/python/
OUTPUT_FILE ${TEST_OUTPUT}
ERROR_VARIABLE TEST_ERROR_VAR
RESULT_VARIABLE TEST_RESULT_VAR
Expand Down