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

CMake: misc #119

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ endmacro
evals
primac
primaf
primafc
cintrf
COBJ
COBJCON
Expand Down
22 changes: 13 additions & 9 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# Fortran object files must be in a separate library as VS generator does not support mixing C and Fortran
add_library (primafc OBJECT cintrf.f90 cobyla_c.f90 lincoa_c.f90 bobyqa_c.f90 newuoa_c.f90 uobyqa_c.f90)
set_target_properties(primafc PROPERTIES POSITION_INDEPENDENT_CODE ON)
Fixed Show fixed Hide fixed
if (NOT BUILD_SHARED_LIBS)
target_link_libraries (primafc INTERFACE ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
endif ()
target_link_libraries (primafc PUBLIC primaf) # must be PUBLIC for precision macros
jschueller marked this conversation as resolved.
Show resolved Hide resolved

set(CMAKE_C_STANDARD 99)

add_library (primac cintrf.f90 cobyla_c.f90 lincoa_c.f90 bobyqa_c.f90 newuoa_c.f90 uobyqa_c.f90 prima.c)
# now the C-only library
add_library (primac prima.c)
if (WIN32)
set_target_properties(primac PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()


target_include_directories (primac PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
target_link_libraries (primac PUBLIC primaf) # must be PUBLIC for precision macros
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is CONFIG added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's to find .mod files in vs, which adds one dir per config

$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>>)
target_link_libraries (primac PRIVATE primafc)
set_target_properties(primac PROPERTIES POSITION_INDEPENDENT_CODE ON C_STANDARD 99)

if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(primac PUBLIC PRIMAC_STATIC)
target_link_libraries (primac INTERFACE ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
endif ()

# Export symbols on Windows. See more comments in fortran/CMakeLists.txt.
Expand All @@ -30,6 +33,7 @@ macro (prima_add_c_test name)
add_executable (example_${name}_c_exe EXCLUDE_FROM_ALL examples/${name}/${name}_example.c)
target_link_libraries (example_${name}_c_exe PRIVATE primac)
target_include_directories (example_${name}_c_exe PRIVATE ${CMAKE_SOURCE_DIR}/c/include)
set_target_properties(example_${name}_c_exe PROPERTIES C_STANDARD 99)
if (PRIMA_ENABLE_EXAMPLES)
set_target_properties (example_${name}_c_exe PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif ()
Expand Down
1 change: 1 addition & 0 deletions c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

macro (prima_add_c_test_multi name)
add_executable(${name}_c_exe EXCLUDE_FROM_ALL ${name}.c)
set_target_properties(${name}_c_exe PROPERTIES C_STANDARD 99)
if (PRIMA_ENABLE_TESTING)
set_target_properties (${name}_c_exe PROPERTIES EXCLUDE_FROM_ALL FALSE)
endif ()
Expand Down