Skip to content

Commit cbaff81

Browse files
committed
Merge remote-tracking branch 'remotes/SuperH-0630/master'
# Conflicts: # CMakeLists.txt
2 parents 6381ad8 + 2592538 commit cbaff81

File tree

3 files changed

+67
-39
lines changed

3 files changed

+67
-39
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,5 @@ pip-log.txt
271271
/windows/VS2019/Debug-*/
272272
/windows/VS2019/Release-*/
273273

274+
.idea
275+
cmake-build*

CMakeLists.txt

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ include (target_arch)
3333

3434
get_target_arch(TARGET_ARCH)
3535

36-
if(${TARGET_ARCH} STREQUAL "ARM")
36+
if(TARGET_ARCH STREQUAL "ARM")
3737
add_definitions(-DPTW32_ARCHARM -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
38-
elseif(${TARGET_ARCH} STREQUAL "ARM64")
38+
elseif(TARGET_ARCH STREQUAL "ARM64")
3939
add_definitions(-DPTW32_ARCHARM64 -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
40-
elseif(${TARGET_ARCH} STREQUAL "x86_64")
40+
elseif(TARGET_ARCH STREQUAL "x86_64")
4141
add_definitions(-DPTW32_ARCHAMD64)
42-
elseif(${TARGET_ARCH} STREQUAL "x86")
42+
elseif(TARGET_ARCH STREQUAL "x86")
4343
add_definitions(-DPTW32_ARCHX86)
44-
elseif(${TARGET_ARCH} STREQUAL "x64")
44+
elseif(TARGET_ARCH STREQUAL "x64")
4545
add_definitions(-DPTW32_ARCHX64)
4646
else()
47-
MESSAGE(ERROR "\"${TARGET_ARCH}\" not supported in version.rc")
47+
MESSAGE(FATAL_ERROR "\"${TARGET_ARCH}\" not supported in version.rc")
4848
endif()
4949
message(STATUS "Target ............ ${TARGET_ARCH}")
5050

@@ -55,10 +55,12 @@ endif()
5555
#################################
5656
# Install Path #
5757
#################################
58-
if(DIST_ROOT)
59-
set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}")
60-
else()
61-
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/PTHREADS-BUILT")
58+
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
59+
if(DIST_ROOT)
60+
set(CMAKE_INSTALL_PREFIX "${DIST_ROOT}")
61+
else()
62+
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/PTHREADS-BUILT")
63+
endif()
6264
endif()
6365
message(STATUS "Install Path ${CMAKE_INSTALL_PREFIX}")
6466

@@ -141,19 +143,34 @@ macro(static_lib type def)
141143
endif()
142144
endmacro()
143145

144-
shared_lib ( VCE PTW32_CLEANUP_CXX )
145-
shared_lib ( VSE PTW32_CLEANUP_SEH )
146-
shared_lib ( VC PTW32_CLEANUP_C )
147146

148-
static_lib ( VCE PTW32_CLEANUP_CXX )
149-
static_lib ( VSE PTW32_CLEANUP_SEH )
150-
static_lib ( VC PTW32_CLEANUP_C )
147+
option(PTHREAD_BUILD_SHARED_LIBRARY "Build shared library" OFF)
148+
set(_build_shared_library ${PTHREAD_BUILD_SHARED_LIBRARY})
149+
set(PTHREAD_BUILD_TYPE "VC" CACHE STRING "VC/VSE/VCE")
150+
151+
if(PTHREAD_BUILD_TYPE STREQUAL "VC")
152+
set(def_ PTW32_CLEANUP_C)
153+
elseif(PTHREAD_BUILD_TYPE STREQUAL "VSE" OR PTHREAD_BUILD_TYPE STREQUAL "VCE")
154+
set(def_ PTW32_CLEANUP_C)
155+
else()
156+
message(FATAL_ERROR "Unsupported pthread type ${PTHREAD_BUILD_TYPE}")
157+
endif()
158+
159+
if(_build_shared_library)
160+
shared_lib (${PTHREAD_BUILD_TYPE} PTW32_CLEANUP_C)
161+
else()
162+
static_lib (${PTHREAD_BUILD_TYPE} PTW32_CLEANUP_C)
163+
endif()
151164

152165
#################################
153166
# Install #
154167
#################################
155168
install(FILES _ptw32.h pthread.h sched.h semaphore.h DESTINATION ${HDRDEST})
156169

170+
message(STATUS "DLLDEST = ${DLLDEST}")
171+
message(STATUS "LIBDEST = ${LIBDEST}")
172+
message(STATUS "HDRDEST = ${HDRDEST}")
173+
157174
#################################
158175
# Test #
159176
#################################
@@ -162,4 +179,6 @@ option(ENABLE_TESTS "Enable Test code build" FALSE)
162179
#TODO determine if cross compile...
163180
if(ENABLE_TESTS)
164181
add_subdirectory(tests)
182+
183+
message(STATUS "TESTDEST = ${TESTDEST}")
165184
endif()

cmake/target_arch.cmake

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11

22
set(TARGET_ARCH_DETECT_CODE "
3-
4-
#if defined(_M_ARM)
5-
#error cmake_arch ARM
6-
#elif defined(_M_ARM64)
7-
#error cmake_arch ARM64
8-
#elif defined(_M_AMD64)
9-
#error cmake_arch x86_64
10-
#elif defined(_M_X64)
11-
#error cmake_arch x64
12-
#elif defined(_M_IX86)
13-
#error cmake_arch x86
14-
#else
15-
#error cmake_arch unknown
3+
int main() {
4+
#if defined(_M_ARM)
5+
return 2;
6+
#elif defined(_M_ARM64)
7+
return 3;
8+
#elif defined(_M_AMD64)
9+
return 4;
10+
#elif defined(_M_X64)
11+
return 5;
12+
#elif defined(_M_IX86)
13+
return 6;
14+
#else
15+
return 0;
1616
#endif
17+
}
1718
")
1819

1920
function(get_target_arch out)
@@ -23,14 +24,20 @@ function(get_target_arch out)
2324
"${TARGET_ARCH_DETECT_CODE}")
2425

2526
try_run(
26-
run_result_unused compile_result_unused
27-
"${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/target_arch_detect.c"
28-
COMPILE_OUTPUT_VARIABLE TARGET_ARCH)
29-
30-
# parse compiler output
31-
string(REGEX MATCH "cmake_arch ([a-zA-Z0-9_]+)" TARGET_ARCH "${TARGET_ARCH}")
32-
string(REPLACE "cmake_arch " "" TARGET_ARCH "${TARGET_ARCH}")
33-
34-
set(${out} "${TARGET_ARCH}" PARENT_SCOPE)
35-
27+
run_result compile_result_unused
28+
"${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/target_arch_detect.c")
29+
30+
if (run_result STREQUAL 2)
31+
set(${out} "ARM" PARENT_SCOPE)
32+
elseif (run_result STREQUAL 3)
33+
set(${out} "ARM64" PARENT_SCOPE)
34+
elseif (run_result STREQUAL 4)
35+
set(${out} "x86_64" PARENT_SCOPE)
36+
elseif (run_result STREQUAL 5)
37+
set(${out} "x64" PARENT_SCOPE)
38+
elseif (run_result STREQUAL 6)
39+
set(${out} "x86" PARENT_SCOPE)
40+
else()
41+
set(${out} "unknown" PARENT_SCOPE)
42+
endif()
3643
endfunction()

0 commit comments

Comments
 (0)